package com.ruoyi.system.utils;

import java.io.File;
import java.util.regex.Pattern;

public class FilePathConverter {
    public static String convertToLocalPath(String httpPath, String serverUrl) {
        String relativePath = httpPath.replaceFirst(Pattern.quote(serverUrl), "");
        String absolutePath = new File("").getAbsolutePath();
        return absolutePath + relativePath;
    }

    public static String convertToHttpPath(String absolutePath, String serverUrl) {
        String relativePath = absolutePath.replaceFirst(Pattern.quote(new File("").getAbsolutePath()), "");
        return serverUrl + relativePath;
    }

    public static void main(String[] args) {
        String serverUrl = "localhost";
        String absolutePath = "path/to/file.txt";

        String httpPath = convertToHttpPath(absolutePath, serverUrl);
        System.out.println("HTTP路径: " + httpPath);

        String localPath = convertToLocalPath(httpPath, serverUrl);
        System.out.println("本地路径: " + localPath);
    }
}